package demo2;

//https://www.nowcoder.com/practice/16d971e9e42e4f3b9b1e2b8794796a43?tpId=308&tqId=40488&ru=/exam/oj
//牛客网: 活动安排

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static boolean[] st = new boolean[20000];
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        Integer[][] actions = new Integer[n][2];
        for(int i = 0; i<n; i++) {
            String[] values = br.readLine().split(" ");
            actions[i][0] = Integer.parseInt(values[0]);
            actions[i][1] =  Integer.parseInt(values[1]);
        }
        Arrays.sort(actions, new Comparator<Integer []>() {
            @Override
            public int compare(Integer[] o1, Integer[] o2) {
                return o1[1] - o2[1];
            }
        });

        int count = 0;
        long end = Integer.MIN_VALUE;
        for(int i = 0; i<n; i++) {
            if(actions[i][0] >= end) {
                count++;
                end = actions[i][1];
            }
        }
        System.out.println(count);
    }
}
